# -*- coding: utf-8 -*-
# @Time        :2024/10/22 下午4:15
# @Author      :文刀水寿
# @File        : 01_pymysql入门.py
"""
 @Description :演示python pymysql库的基础操作
"""
from pymysql import Connection

# 构建到MYSQL数据库的连接
conn = Connection(
    host='localhost',
    port=3306,
    user='root',
    password='1028',
    autocommit=True
)
# print(conn.get_server_info())
# 执行非查询性质sql
cursor = conn.cursor()  # 获取游标对象
# 选择数据库
conn.select_db("scrapy使用手册")
# 执行sql
cursor.execute("create table test_pymysql(id int);")

# 执行查询性质sql
cursor.execute("select * from scrapy使用手册;")

# 获取查询结果
result: tuple = cursor.fetchall()
for r in result:
    print(r)
# 关闭链接
conn.close()
